package com.generator;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipOutputStream;

import org.apache.commons.io.IOUtils;

import com.generator.util.GenDBUtil;
import com.generator.util.GenUtils;


public class GeneratorMain {
	//生成代码
	public static void main(String[] args) {
		System.out.println("=====================代码生成开始=======================");
		ZipOutputStream zip = null;
		try {
			zip = new ZipOutputStream(new FileOutputStream("D:\\GeneratorCode.zip"));
			String tableNames[] = {"user","role","menu"};
			for(String tableName : tableNames){
				System.out.println("=====================正在为"+tableName+"表生成代码=======================");
				//查询表信息
				Map<String, String> tableObj = GenDBUtil.getGenDBUtil().queryTableInfo(tableName);
				//查询列信息
				List<Map<String, String>> columns = GenDBUtil.getGenDBUtil().queryColumns(tableName);
				GenUtils.generatorCode(tableObj, columns, zip);
			}
			IOUtils.closeQuietly(zip);
			System.out.println("=====================代码生成结束=======================");
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				if(zip != null){
					zip.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
